//
//  MeTabBarViewController.m
//  MeLive
//
//  Created by liulei on 2017/5/2.
//  Copyright © 2017年 liulei. All rights reserved.
//

#import "MeTabBarViewController.h"
#import "MeNavigationViewController.h"
#import "MeHotViewController.h"
#import "MeMyCenterViewController.h"
#import "MeTabBar.h"
#import "MeLivePushViewController.h"

@interface MeTabBarViewController ()<MeTabBarDelegate>
@property (nonatomic, strong) MeHotViewController *homeVc;
@property (nonatomic, strong) MeMyCenterViewController *profileVc;
@end

@implementation MeTabBarViewController

#pragma mark - life cycle
- (void)viewDidLoad {
    [super viewDidLoad];
    
    // 添加子控制器
    [self addChildVc:self.homeVc title:@"直播" image:@"toolbar_home" selectedImage:@"toolbar_home_sel"];
    [self addChildVc:self.profileVc title:@"关注" image:@"toolbar_me" selectedImage:@"toolbar_me_sel"];
    
    MeTabBar *tabBar = [[MeTabBar alloc] init];
    tabBar.customDelegate = self;
    /** KVC */
    [self setValue:tabBar forKey:@"tabBar"];
}

#pragma mark - delegate
// MainTabBarControllerTabBarDelegate 加号按钮代理
- (void)tabBarDidClickPlusButton:(MeTabBarViewController *)tabBar
{
    MeLivePushViewController *pushVc = [[MeLivePushViewController alloc] init];
    MeNavigationViewController *navigationVc = [[MeNavigationViewController alloc] initWithRootViewController:pushVc];
    [self presentViewController:navigationVc animated:YES completion:nil];
}
#pragma mark - event response
#pragma mark - private methods
- (void)addChildVc:(UIViewController *)childVc title:(NSString *)title image:(NSString *)image selectedImage:(NSString *)selectedImage
{
    
    /** 设置tabbar title  和 navigationbar title */
    childVc.title = title;
    [childVc.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor redColor]} forState:UIControlStateSelected];
    /** 设置图片 */
    childVc.tabBarItem.image = [UIImage imageNamed:image];
    childVc.tabBarItem.selectedImage = [[UIImage imageNamed:selectedImage] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    /** 添加子控制器 */
    MeNavigationViewController *navigationVc = [[MeNavigationViewController alloc] initWithRootViewController:childVc];
    [self addChildViewController:navigationVc];
}
#pragma mark - getters and setters
- (MeHotViewController *)homeVc
{
    if (_homeVc == nil) {
        _homeVc = [[MeHotViewController alloc] init];
    }
    return _homeVc;
}
- (MeMyCenterViewController *)profileVc
{
    if (_profileVc == nil) {
        _profileVc = [[MeMyCenterViewController alloc] init];
    }
    return _profileVc;
}
@end
